package cn.edu.cdp.service.impl;

import cn.edu.cdp.domain.User;
import cn.edu.cdp.mapper.UserMapper;
import cn.edu.cdp.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void add(User user) {
        if(user.getGender() == null || user.getGender() == ""){
            user.setGender("男");
        }
        userMapper.add(user);
    }

    @Override
    public List<User> findAll() {
       List<User> userList = new ArrayList<User>();
       userList = userMapper.findAll();

       return userList;
    }

    @Override
    public void delete(String id) {
        userMapper.delete(Integer.parseInt(id));
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }
}
